<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
      @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input clearable style="width: 240px" v-model="queryParams.search.no" placeholder="请输入出库单号"
          clearable></el-input>
      </el-form-item>
      <!-- <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.search.status" placeholder="状态" clearable style="width: 100%">
          <el-option v-for="(i,index) in ['未开启','运营中']" :key="index" :label="i"
            :value="index" />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" >新增</el-button>
      </el-col>
      
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getDataList"></right-toolbar>
    </el-row>
    <el-table :data="dataList" v-loading="loading" style="width: 100%;">
      
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="no" label="编号" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="associationNo" label="关联编号" align="center"  />
      <el-table-column prop="outboundDate" label="出库日期" align="center"/>
      <el-table-column prop="outboundUserId"  label="出库人" align="center" width="300"/>
      <el-table-column prop="status" label="状态" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1">待确认</span>
          <span v-if="scope.row.status == 2">已确认</span>
          <span v-if="scope.row.status == 4">已作废</span>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" align="center" :show-overflow-tooltip="true" />
      
      <el-table-column label="操作" fixed="right" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-view" @click="preview(scope.row)"
            v-hasPermi="['business:driver:list']">查看</el-button> -->
          <el-button size="mini" type="text" @click="preview(scope.row)"
            v-hasPermi="['business:driver:list']">查看</el-button>
          <el-button size="mini" type="text"  @click="handleDelete(scope.row)"
            v-hasPermi="['business:driver:list']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getDataList" />
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    
    <el-dialog title="商户信息" :visible.sync="showInfo" width="60%">
      <h3>基本信息</h3>
      <el-descriptions :column="3">
      
          <el-descriptions-item label="仓库" prop="name">{{info.stockHouseName}}</el-descriptions-item>
          <el-descriptions-item label="出库时期" prop="outboundDate">{{info.outboundDate}}</el-descriptions-item>
          <!-- <el-descriptions-item label="生成方式" prop="createType">
            <el-select v-model="dataForm.createType" placeholder="请选择生成方式" clearable style="width: 100%">
              <el-option v-for="(item,index) in createTypes" :key="index" :disabled="item.disabled"
                :label="item.label" :value="item.value" />
            </el-select>
          </el-descriptions-item> -->
          
          <!-- <el-descriptions-item label="状态" prop="status">
            <el-select v-model="dataForm.status" placeholder="请选择状态" clearable style="width: 100%">
              <el-option v-for="(item,index) in ['待出库','已出库','已作废']" :key="index" :label="item" :value="index" />
            </el-select>
          </el-descriptions-item> -->
          
          <!-- <el-descriptions-item label="支付状态" prop="payStatus">{{}}</el-descriptions-item> -->
          
          <el-descriptions-item label="支付方式" prop="payType">{{info.payType}}</el-descriptions-item>
          
          <el-descriptions-item label="出库人" prop="outboundUserId">{{info.outboundUserId}}</el-descriptions-item>
          
          <el-descriptions-item label="支付金额" prop="payAmount">{{info.payAmount}}</el-descriptions-item>
          
          <el-descriptions-item label="出库单号" prop="no">{{info.no}}</el-descriptions-item>

      </el-descriptions>

      <h3>货品清单</h3>
      
      <el-table :data="info.outboundListDetailList" style="margin-top:20px">
        <el-table-column prop="goodsName" label="商品名称" width="500" align="center"/>
        <el-table-column prop="unit" label="单位" align="center"/>
        <el-table-column label="出库数量" prop="quantity" align="center"></el-table-column>
        <el-table-column prop="sellingPrice" label="单价" align="center"/>
        <el-table-column prop="sellingPrice" label="售价" align="center"/>
      </el-table>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="showInfo = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import {
    page,
    deleteById
  } from "@/api/business/stock/outbound";
  
  import AddOrUpdate from './addOrUpdate'
import { mapState } from 'vuex';
  export default {
    computed:{
      ...mapState({
          sysUser: state => state.user.sysUser,
        })
    },
    data() {
      return {
        showInfo: false,
        info: {},
        loading: true,
        loading2: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        // 总条数
        total: 0,
        //表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 表单参数
        // 显示搜索条件
        showSearch: true,
        form: {},
        // 日期范围
        dateRange: [],
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          search: {
            keyword: '',
          }
        },
        dataList: [],
        rules: {},
        addOrUpdateVisible: false,
        orderList: [],
        comerecordList: [],
        dataDate: []
      }
    },
    components: {
      AddOrUpdate
    },
    created() {
      this.getDataList();
      this.initPage();
    },
    methods: {
      
      initPage() {

      },
      changeDataType(e) {
        this.dataDate = [];
        if (e.name == '1') {
          this.getDriver();
        } else if (e.name == '2') {
          this.getIncomes();
        }
      },
      onDateChange(e) {
        this.getIncomes();
      },
      
      preview(e) {
        this.loading2 = true
        this.info = e;
        this.showInfo = true;
      },
      // 获取数据列表
      getDataList() {
        this.loading = true;
        this.queryParams.search.stockHouseId = this.sysUser.agentId
        
        page(this.queryParams).then(response => {
          this.dataList = response.data.list;
          this.total = parseInt(response.data.total);
          this.loading = false;
        }).catch(res => {
          this.loading = false
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getDataList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.userId);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.addOrUpdateVisible = true;
        this.title = "添加";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init({})
        })
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.addOrUpdateVisible = true;
        this.title = "修改";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(row)
        })
      },
      handleDelete(row) {
        const ids = row.id;
        this.$modal.confirm('确定要删除选中的数据项？').then(function() {
          return deleteById(ids);
        }).then(() => {
          this.getDataList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          search: {
            keyword: '',
            franchiseeId: ''
          }
        };
        this.getDataList()
      }
    }
  }
</script>
<style lang="scss" scoped>
  .driver_data {
    position: relative;

    .date {
      position: absolute;
      top: 0;
      right: 0;
      z-index: 1;
    }
  }
</style>
